<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;
class Read extends Common
{
    public function index()
    {
        $id=$this->request->param('id');
        $id=(int)$id;
        $sql="select * from tp_activity where id=$id";
        $activity=Db::query($sql);
        $this->view->assign('ac',$activity);
        $sql2="select * from tp_comment where activity_id=$id";
        $comment=Db::query($sql2);
        $this->view->assign('co',$comment);
        return view();
    }
    public function readnews()
    {
        $id=$this->request->param('id');
        echo $id;
        $sql="select * from tp_notice where id=$id";
        $activity=Db::query($sql);
       // dump($activity);
        $this->view->assign('ac',$activity);
        /* $sql2="select * from tp_comment where activity_id=$id";
        $comment=Db::query($sql2);
        $this->view->assign('co',$comment);*/
        return view();
    }
    public function readwork()
    {
        $id=$this->request->param('id');
        echo $id;
        $sql="select * from tp_work where id=$id";
        $activity=Db::query($sql);
        // dump($activity);
        $this->view->assign('ac',$activity);
        /* $sql2="select * from tp_comment where activity_id=$id";
         $comment=Db::query($sql2);
         $this->view->assign('co',$comment);*/
        return view();
    }
    public function insert()
    {
        $data=$this->request->post();
        if(!empty($data['comment']))
        {
            //敏感词过滤
            $data['comment'] = $this->setKeyWord($data['comment']);
            $data['create_time'] = time();
            $data['update_time'] = time();
            $data['status']=1;
            $data['isdelete']=0;
            $data['time'] = date('Y-m-d H:i:s');
            $result= Db::name("comment")->insert($data);
            if($result!=false)
            {
              $this->success("发表成功");
            }else
            {
               $this->error("发表失败");
            }
        }
        else{
            $this->error("无效的评论");
        }
    }
}
